//
//  HZNavHeaderView.m
//  HZTC_Stock
//
//  Created by MayerF on 17/3/19.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZNavHeaderView.h"

@interface HZNavHeaderView()
@property (nonatomic, strong)UILabel *pTitleLabel;
@property (nonatomic, strong)UILabel *pCodeLabel;
@property (nonatomic, strong)UIImageView *pImageView;
@end

@implementation HZNavHeaderView

#pragma mark -
#pragma mark 生命周期
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self p_commonInit];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
#pragma mark -
#pragma mark private
- (void)p_commonInit
{
    _pTitleLabel = [UILabel new];
    _pCodeLabel = [UILabel new];
    _pImageView = [UIImageView new];
    _pTitleLabel.backgroundColor = [UIColor clearColor];
    _pCodeLabel.backgroundColor = [UIColor clearColor];
    _pTitleLabel.textAlignment = _pCodeLabel.textAlignment = NSTextAlignmentCenter;
    _pTitleLabel.textColor = _pCodeLabel.textColor = [UIColor blackColor];
    _pCodeLabel.font = [UIFont systemFontOfSize:13];
    _pCodeLabel.hidden = YES;
    
    [self addSubview:_pTitleLabel];
    [self addSubview:_pCodeLabel];
    
    [self p_initConstraints];
}

- (void)p_initConstraints
{
    [_pTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self);
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(self);
        make.bottom.mas_equalTo(_pCodeLabel.mas_top);
    }];
    [_pCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(self);
        make.bottom.mas_equalTo(self);
        make.height.mas_equalTo(_pTitleLabel);
    }];
//    [_pImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self);
//        make.left.mas_equalTo(self);
//        make.right.mas_equalTo(self);
//        make.bottom.mas_equalTo(_pCodeLabel.mas_top);
//    }];
}

- (CGSize)intrinsicContentSize {
    return CGSizeMake(CGRectGetWidth(self.frame), 40);
}

- (void)updateCodeInfo:(HZOwnedStockModel *)codeInfo
{
    _pTitleLabel.text = codeInfo.model_Name;
    if (codeInfo.nModel_isR) {
        _pCodeLabel.text = [NSString stringWithFormat:@"%@融",codeInfo.model_Code];
        NSMutableAttributedString *strAtr = [[NSMutableAttributedString alloc] initWithString:_pCodeLabel.text];
        [strAtr addAttribute:NSBackgroundColorAttributeName value:kMYHexToRGB(0xf7b21c, 1) range:NSMakeRange(_pCodeLabel.text.length - 1, 1)];
        [strAtr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(_pCodeLabel.text.length - 1, 1)];
        _pCodeLabel.attributedText = strAtr;
    }else {
        _pCodeLabel.text = codeInfo.model_Code;
    }
}

- (void)updateTitleName:(NSString *)titleName{
    _pTitleLabel.text = titleName;
    _pCodeLabel.hidden = YES;
    [_pTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self);
    }];
}
@end
